home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_222 / plplot / src / source.zoo / pldeco.c < prev    next >
C/C++ Source or Header  |  1989-05-15  |  4KB  |  128 lines

  1. /* Decode a character string, and return an array of integer symbol */
  2. /* numbers. This routine is responsible for interpreting all escape */
  3. /* sequences. At present the following escape sequences are defined */
  4. /* (the letter following the \ may be either upper or lower case): */
  5.  
  6. /* \u       :      up one level (returns -1) */
  7. /* \d       :      down one level (returns -2) */
  8. /* \b       :      backspace (returns -3) */
  9. /* \+       :      toggles overline mode (returns -4) */
  10. /* \-       :      toggles underline mode (returns -5) */
  11. /* \\       :      \, returns the code for backslash */
  12. /* \gx      :      greek letter corresponding to roman letter x */
  13. /* \fn      :      switch to Normal font */
  14. /* \fr      :      switch to Roman font */
  15. /* \fi      :      switch to Italic font */
  16. /* \fs      :      switch to Script font */
  17. /* \(nnn)   :      Hershey symbol number nnn (any number of digits) */
  18.  
  19. #include "plplot.h"
  20. #include <stdio.h>    /* include for definition of NULL */
  21. #include <string.h>
  22.  
  23. static char font[] = "nrisnris";
  24. static char greek[] = "ABGDEZYHIKLMNCOPRSTUFXQWabgdezyhiklmncoprstufxqw";
  25.  
  26. extern short int *hersh[];
  27.  
  28. void pldeco(symbol,length,text)
  29. int symbol[],*length;
  30. char text[];
  31. {
  32.       int ch,icol,ifont,ig,j,lentxt;
  33.       char test;
  34.  
  35.       /* Initialize parameters. */
  36.  
  37.       lentxt=strlen(text);
  38.       *length=0;
  39.       j=0;
  40.       gatt(&ifont,&icol);
  41.  
  42.       /* Get next character; treat non-printing characters as spaces. */
  43.  
  44. lab100:
  45.       j=j+1;
  46.       if (j>lentxt) return;
  47.       test=text[j-1];
  48.       ch=test;
  49.       if (ch<0)   ch = 32;
  50.  
  51.       if (ch>175) ch = 32;
  52.  
  53.       /* Test for escape sequence (\) */
  54.  
  55.       if (ch=='\\') {
  56.         if ((lentxt-j)>=1) {
  57.           test=text[j];
  58.           if (test=='\\')
  59.             j = j+1;
  60.           else if (test=='U' || test=='u') {
  61.             *length = *length + 1;
  62.             symbol[*length-1] = -1;
  63.             j = j+1;
  64.             goto lab100;
  65.           }
  66.           else if (test=='D' || test=='d') {
  67.             *length = *length + 1;
  68.             symbol[*length-1] = -2;
  69.             j = j+1;
  70.             goto lab100;
  71.           }
  72.           else if (test=='B' || test=='b') {
  73.             *length = *length + 1;
  74.             symbol[*length-1] = -3;
  75.             j = j+1;
  76.             goto lab100;
  77.           }
  78.           else if (test=='+') {
  79.             *length = *length + 1;
  80.             symbol[*length-1] = -4;
  81.             j = j+1;
  82.             goto lab100;
  83.           }
  84.           else if (test=='-') {
  85.             *length = *length + 1;
  86.             symbol[*length-1] = -5;
  87.             j = j+1;
  88.             goto lab100;
  89.           }
  90.           else if (test=='(') {
  91.             *length = *length + 1;
  92.             symbol[*length-1] = 0;
  93.             j = j+2;
  94. lab10:
  95.             if ('0'<=text[j-1] && text[j-1]<='9') {
  96.               symbol[*length-1] = symbol[*length-1]*10 + text[j-1] - '0';
  97.               j = j+1;
  98.               goto lab10;
  99.             }
  100.             if (text[j-1]!=')') j = j-1;
  101.             goto lab100;
  102.           }
  103.           else if (test=='F' || test=='f') {
  104.             test=text[j+1];
  105.             ifont = strpos(font,test) + 1;
  106.             if (ifont>4) ifont = ifont-4;
  107.             if (ifont==0) ifont = 1;
  108.             j = j+2;
  109.             goto lab100;
  110.           }
  111.           else if (test=='G' || test=='g') {
  112.             test=text[j+1];
  113.             ig = strpos(greek,test) + 1;
  114.             *length = *length + 1;
  115.             symbol[*length-1] = *(hersh[ifont-1] + 127 + ig);
  116.             j = j+2;
  117.             goto lab100;
  118.           }
  119.         }
  120.       }
  121.  
  122.       /* Decode character. */
  123.  
  124.       *length = *length + 1;
  125.       symbol[*length-1] = *(hersh[ifont-1]+ch);
  126.       goto lab100;
  127. }
  128.